// src/mixins/commonMethods.js
export default {
  methods: {
    // 表格选中变化
    handleSelectionChange(selection) {
      this.selectedRows = selection.map(row => row.id);
    },

    // 表格行样式
    tableRowClassName({ rowIndex }) {
      return rowIndex % 2 === 1 ? 'even-row' : '';
    },

    // 切换页数
    changePageIndex(newPageIndex) {
      this.queryParams.pageIndex = newPageIndex - 1;
      this.getList(); // 假设每个页面都有 getList 方法加载数据
    },

    // 切换条数
    changePageSize(newPageSize) {
      this.queryParams.pageSize = newPageSize;
      this.queryParams.pageIndex = 0; // 切换条数时重置页码
      this.getList();
    },

    // 检查权限
    hasPermission(permissionCode) {
      const userPermissions = this.$store.state.user.userInfo?.powers || [];
      return userPermissions.some(point => point.code === permissionCode);
    },

    // 重置查询参数
    reset() {
      this.queryParams = {
        sortType: '3',
        pageIndex: 0,
        pageSize: 10,
        name: '',
        phone: '',
        keyword: '',
      };
    },
  },
};